//
//  HomeTableHeaderView.m
//  AppointmentForCar
//
//  Created by TheMacBook on 2016/11/7.
//  Copyright © 2016年 Herron. All rights reserved.
//

#import "HomeTableHeaderView.h"

@implementation HomeTableHeaderView {
    UIImageView * _iconImage;
    UILabel * _nameLabel;
    UILabel * _phoneLabel;
    HomeHeaderItem * _orderCount;
    HomeHeaderItem * _billboard;
    UILabel * _statusLabel;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        self.backgroundColor = [UIColor clearColor];
        _iconImage  = [[UIImageView alloc] initWithImage:nil];
        _iconImage.layer.cornerRadius = kScaleWidth(76)/2;
        _iconImage.layer.masksToBounds = YES;
        _iconImage.layer.borderColor = [UIColor colorWithString:@"#9596A3"].CGColor;
        _iconImage.layer.borderWidth = 3;
        _statusLabel = [[UILabel alloc] init];
        _statusLabel.layer.cornerRadius = 3;
        _statusLabel.layer.masksToBounds = YES;
        _statusLabel.layer.borderWidth = 1;
        _statusLabel.layer.borderColor = kColorSystem.CGColor;
        _statusLabel.textColor = kColorSystem;
        _statusLabel.textAlignment = NSTextAlignmentCenter;
        _statusLabel.font = [UIFont systemFontOfSize:15];
        _nameLabel  = [[UILabel alloc] init];
        _phoneLabel = [[UILabel alloc] init];
        _orderCount = [[HomeHeaderItem alloc] init];
        _billboard  = [[HomeHeaderItem alloc] init];
        UIView * line = [[UIView alloc] init];
        UIView * bottomLine = [[UIView alloc] init];

        self.addSubview(_iconImage).addSubview(_nameLabel).addSubview(_phoneLabel).addSubview(_orderCount).addSubview(_billboard).addSubview(line).addSubview(bottomLine).addSubview(_statusLabel);
        
        // setup
        _nameLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:kFontSize(20)];
        _phoneLabel.font = kAppFontSize(15);
        line.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
        bottomLine.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
        _nameLabel.textColor = [UIColor whiteColor];
        _phoneLabel.textColor = [UIColor whiteColor];
        _orderCount.title = @"订单数";
        _billboard.title = @"排行榜";
        // layout
        __weak typeof(self) weakSelf = self;
        [_iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo((CGSize){kScaleWidth(76),kScaleWidth(76)});
            make.top.equalTo(weakSelf.mas_top).mas_offset(kScaleHeight(25));
            make.bottom.equalTo(line.mas_top).mas_offset(-kScaleHeight(25));
            make.left.equalTo(weakSelf.mas_left).mas_offset(kScaleWidth(50));
        }];
        
        [_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(26);
            make.width.mas_equalTo(58);
            make.centerY.equalTo(_nameLabel.mas_centerY);
            make.right.equalTo(weakSelf).mas_offset(-15);
        }];

        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_iconImage.mas_right).mas_offset(kScaleWidth(20));
            make.top.equalTo(_iconImage.mas_top).mas_offset(10);
        }];
        [_phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_nameLabel.mas_left);
            make.bottom.equalTo(_iconImage.mas_bottom).mas_offset(-10);
        }];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0.5);
            make.left.equalTo(weakSelf).mas_offset(10);
            make.right.equalTo(weakSelf).mas_offset(-10);
        }];
        [_orderCount mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(_billboard.mas_width);
            make.top.equalTo(line.mas_bottom);
            make.right.equalTo(_billboard.mas_left);
            make.left.equalTo(weakSelf.mas_left);
            make.bottom.equalTo(weakSelf.mas_bottom);
            make.height.mas_equalTo(kScaleHeight(60));
        }];
        [_billboard mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(_orderCount);
            make.right.equalTo(weakSelf.mas_right);
        }];
        [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0.5);
            make.left.right.bottom.equalTo(weakSelf);
        }];


}
    return self;
}
- (void)setModel:(DriverModel *)model {
    _model = model;
    _nameLabel.text = model.driverNickName;
    _phoneLabel.text = model.driverPhoneNumber;
    _orderCount.count = [model.orderNumber integerValue];
    _billboard.count = [model.rankList integerValue];
    _iconImage.urlPath = model.driverAvatarUrl;
    if (1 == model.status) {
        _statusLabel.text = @"已通过";
    } else if (2 == model.status) {
        _statusLabel.text = @"未通过"; 
    } else {
        _statusLabel.text = @"审核中";
    }
}

- (void)setupIcon:(NSString *)image {
    _iconImage.urlPath = image;
}

- (void)setupName:(NSString *)name {
    _nameLabel.text = name;
}

@end

@implementation HomeHeaderItem
{
    UILabel * _countLabel;
    UILabel * _titleLabel;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        self.backgroundColor = [UIColor clearColor];
        _countLabel = [[UILabel alloc] init];
        _titleLabel = [[UILabel alloc] init];
       
        self.addSubview(_countLabel).addSubview(_titleLabel);
        // setup
        _countLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _countLabel.textColor = [UIColor whiteColor];
        _titleLabel.textColor = [UIColor whiteColor];
        _countLabel.font = [UIFont systemFontOfSize:20];
        // layout
        __weak typeof(self) weakSelf = self;
        [_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(weakSelf);
            make.top.mas_greaterThanOrEqualTo(kScaleHeight(6));
        }];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(weakSelf);
            make.bottom.mas_greaterThanOrEqualTo(kScaleHeight(-10));
        }];
    }
    return self;
}
- (void)setTitle:(NSString *)title
{
    _title = title;
    _titleLabel.text = title;

}
- (void)setCount:(NSInteger)count
{
    _count = count;
    _countLabel.text = [NSString stringWithFormat:@"%ld",(long)count];
}



@end
